home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’92 / PatchWorks Kit / Examples / MPW Example / Example.c next >
Encoding:
C/C++ Source or Header  |  1992-05-16  |  1.4 KB  |  71 lines  |  [TEXT/MPS ]

  1. /*
  2.     Example.c
  3.     
  4.     Example extension. Demonstrates use of PatchWorks trap patching
  5.     system to patch MenuSelect. Uses new GenericPatch class.
  6.     
  7.     by Mouse Herrell & Patrick Beard.
  8.     
  9.     © 1991 Berkeley Systems Inc.
  10. */
  11.  
  12. #include <string.h>
  13. #include <Notification.h>
  14. #include <Traps.h>
  15. #include <stdarg.h>
  16. #include <stdio.h>
  17. #include <stddef.h>
  18. #include <Events.h>
  19. #include <Strings.h>
  20. #include <strstream.h>
  21.  
  22. #include "ShowIconFamily.h"
  23. #include "Exceptions.h"
  24. #include "Extension.h"
  25. #include "Example.h"
  26.  
  27. MenuSelectPatch::MenuSelectPatch()
  28. {
  29.     itsCallCount = 0;
  30.     GenericPatch::InitGenericPatch(_MenuSelect, offsetof(MenuSelectParameters, itsResult));
  31.     Install();
  32. }
  33.  
  34. void MenuSelectPatch::Behavior()
  35. {
  36.     KeyMap Keys;
  37.     
  38.     // announce our presence & abort the trap if control key held down.
  39.     ++itsCallCount;
  40.     GetKeys(Keys);
  41.     if (Keys[1] & 0x8) {
  42.         MenuSelectParameters* params = (MenuSelectParameters*)itsFrame->parameters;
  43.         params->itsResult = 0;
  44.         AbortTrap();
  45.         strstream message;
  46.         Point& pt = params->itsStartPt;
  47.         message << "MenuSelect:  startPt = (" << pt.h << ", " << pt.v << "), " << itsCallCount << " calls." << '\0';
  48.         debugstr(message.str());
  49.     }
  50. }
  51.  
  52. void Install()
  53. {
  54.     try {
  55.         // if extension succeeds, show happy icon.
  56.         new MenuSelectPatch;
  57.         ShowIconFamily(128);
  58.     } catch {
  59.         // extension failed, show sad icon.
  60.         ShowIconFamily(129);
  61.         throw(theException);
  62.     }
  63. }
  64.  
  65. // called when system is shutdown.
  66.  
  67. void Remove()
  68. {
  69.     Patch::RemoveAll();
  70. }
  71.